package ch1;

import java.util.*;

public class ListTest1 {

	public static void main(String[] args) {
		List list = new ArrayList();
		list.add("cat");
		list.add("dog");
		list.add(2, "snake");
		list.add("pig");
		System.out.println(list);
		list.add("dog");
		list.add(Math.PI);
		System.out.println(list);
		System.out.println("元素个数：" + list.size());
		// get根据下标获得元素
		Object o = list.get(2);
		System.out.println("第三个位置上是：" + o);
		System.out.println(">>>>>>>>>>>>>>>>>");
		for (int i = 0; i < list.size(); i++) {
			System.out.println(i + ":" + list.get(i));
		}
		System.out.println("删除测试：");
		Object r = list.remove(4);
		System.out.println(r + " 从集合中删除了。。。");
		System.out.println(list);
		System.out.println("是否包含：");
		boolean in = list.contains("pig");

		System.out.println("猪在不在？" + in);
		int pos = list.indexOf("pig");
		System.out.println("位置在 ：" + pos);
	}

}
